<!doctype html>
<html>

	<head>
		<title>登录</title>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<meta name="viewport" content="initial-scale=1.0, minimum-scale=1.0, maximum-scale=2.0, user-scalable=no, width=device-width">
		<meta name="format-detection" content="telephone=no">
		<link rel="stylesheet" href="assets/css/amazeui.min.css">
		<link rel="stylesheet" href="assets/css/style.css">
		<script type="text/javascript" src="assets/js/jquery-1.9.0.min.js"></script>
		<script type="text/javascript" src="assets/js/allUse.js"></script>
		<script src="assets/js/jquery.md5.js"></script>
		<script src="assets/js/allUse.js"></script>
		<!--<script type="text/javascript" src="http://qzonestyle.gtimg.cn/qzone/openapi/qc_loader.js" data-appid="appid" data-redirecturi="index.html" charset="utf-8"></script>--> 
		<!--<script src="http://res.wx.qq.com/connect/zh_CN/htmledition/js/wxLogin.js"></script>
		<script type="text/javascript" src="http://qzonestyle.gtimg.cn/qzone/openapi/qc_loader.js" data-appid="1106234995" data-redirecturi="http://wujiutest.ngrok.cc/qc_callback.html" charset="utf-8"></script>-->
		<!--<script type="text/javascript"src="http://qzonestyle.gtimg.cn/qzone/openapi/qc_loader.js" charset="utf-8" data-callback="true"></script>-->
		<style type="text/css">
			iframe{
				width: 100%;
				height: 100%;
			}
			body{
				overflow: hidden;
			}
			.containter{
				height: 100%;
			}
			#QR_code{
				height: 100%;
				position: fixed;
				width: 100%;
				height:100%;
				top: 0rem;
				left: 0;
				right:0;
				bottom:0;
				display:none;
				background:rgba(0,0,0,0.5);
				z-index: 100000000;
				padding-top: 4rem;
				
			}
			#qqLogin::after{
				content: "QQ";
				color: #fff;
			}
		</style>
		<script type="text/javascript">
			$(document).ready(function() {
				
				var regn = /^[0-9]*$/
				$("#phonenumber").on("keyup",function(){
					if(!regn.test($(this).val())){
						$(this).val($(this).val().substring(0,$(this).val().length-1))
					}
				})
				function isWeiXin(){//判断是否是在微信浏览器  是 返回 true
				var ua = window.navigator.userAgent.toLowerCase(); 
					if(ua.match(/MicroMessenger/i) == 'micromessenger'){ 
						return true; 
					}else{ 
						return false; 
					} 
				}
				if(isWeiXin()){//微信浏览器中
					
				}else{
					$("ol").css({"padding":"0"})
					$("#WxLogin").hide();
					$("#qqLogin").css({"margin":"auto","float":"initial"});
				}
				//登录页面-密码显示
				$(".close").click(function() {
					$(this).toggleClass("close");
					$(this).toggleClass("key");
					if($(this).is('.key')) {
						$(this).parents("li").find("input").attr("type", "text");
					} else {
						
						$(this).parents("li").find("input").attr("type", "password");
					}
				});
				$("#jToreg").click(function(){
					sessionStorage.setItem('registerBack',document.referrer);
					console.log(document.referrer);
					window.location.href="register.html"
				})
				//以下5.3用户登录
				var loginFlag=true
				if(localStorage.getItem("token")){
					
					window.sessionStorage.setItem("user_id",localStorage.getItem("user_id"));
					window.sessionStorage.setItem("token",localStorage.getItem("token"));
					console.log(localStorage.getItem("token"));
					myTr(localStorage.getItem("token"))
				}else{
					$('.btn_login').click(function() {
						var phone_num = $.trim($("#phonenumber").val());//手机号码
						var pass_word = $.md5($.md5($.trim($("#pass_word").val())));//密码
						var rxPhone = /^1[3|4|5|7|8][0-9]{9}$/;
						if(!phone_num){
							showToast("请输入手机号")
							return;
						}else if(!rxPhone.test(phone_num)){
							showToast("手机号码有误")
							return;
						}else if(!$.trim($("#pass_word").val())){
							showToast("请输入密码")
							return;
						}else if(!loginFlag){
							return;
						}else{
							login(phone_num,pass_word,1)
						}
						
					});
				}
				//以上用户登录
				//以下三方登陆 qq
				QQlogin(false)//暂时封印三方登录功能
				function QQlogin(flag){
					if(flag){
						QC.Login({
					       btnId:"qqLogin",	//插入按钮的节点id
					       size:"C_S"
						})
						var paras = {};
						QC.api("get_user_info", paras)
							.success(function(s){
							//成功回调，通过s.data获取OpenAPI的返回数据
							alert("获取用户信息成功！当前用户昵称为："+s.data.nickname);
						})
						//指定接口访问失败的接收函数，f为失败返回Response对象
						.error(function(f){
							//失败回调
							console.log(f);
							alert("获取用户信息失败！");
						})
						//指定接口完成请求后的接收函数，c为完成请求返回Response对象
						.complete(function(c){
							//完成请求回调
							console.log(c);
							alert("获取用户信息完成！");
						});
							}
				}
//				$("#qqLogin").click(function(){
//					 var A=window.open("assets/js/index.php","TencentLogin", "width=450,height=320,menubar=0,scrollbars=1,resizable=1,status=1,titlebar=0,toolbar=0,location=1");
//				})
				//以上 三方登陆QQ
				//以下微信三方登陆
//				if(GetQueryString("code") && GetQueryString("state")==window.sessionStorage.getItem("random_num")){//回调成功
//					var code=GetQueryString("code");
////					window.location.href="https://api.weixin.qq.com/sns/oauth2/access_token?appid=wx8110ffb151e28132&secret=717c1c51b9a0774e836e1163e219f831&code="+code+"&grant_type=authorization_code"
//					$.ajax({
//						type:"JSONP",
//						url:"https://api.weixin.qq.com/sns/oauth2/access_token",
//						async:true,
//						data:{
//							appid:"wx8110ffb151e28132",
//							secret:"717c1c51b9a0774e836e1163e219f831",
//							code:""+code+"",
//							grant_type:"authorization_code"
//						},
//						success:function(data){
//							console.log(data)
//						}
//					});
//				}else if(!GetQueryString("code") && GetQueryString("state")==window.sessionStorage.getItem("random_num")){
//					console.log("用户禁止授权");
//				}else{//可能遭遇攻击
//					console.log("可能遭遇攻击")
//					return;
//				};
//				$("#WxLogin").click(function(){
//					$("#QR_code").toggle();
//					var random_num=parseInt(Math.random()*9000+1000);
//					var url="http://wujiutest.ngrok.cc/wx_callback.html"
//					window.sessionStorage.setItem("random_num",random_num);
//				 	 var obj = new WxLogin({
//				 	 	 	id:"QR_code", 
//                        appid: "wx8110ffb151e28132", 
//                        scope: "snsapi_login", 
//                        redirect_uri:encodeURI(url),
//                        state: random_num,
//                        style: "black",
//				 	 });
//				 	
//				});
				//以上微信三方登陆
				function login(phone_num,pass_word,type){
					loginFlag=false;
					$.ajax({
						type: "post",
						url: url_enter+"/api/login",
						data: {
							"login_type":type, //登录类型，1为手机号加密码，2为QQ登录，3为微信登录，根据登录类型传参不定，整数类型（Int）
							"phone_num":phone_num, //用户手机号，login_type为1时有该字段，字符串类型（String）
							"password":pass_word, //用户密码，未加密，login_type为1时有该字段，字符串类型（String）
						},
						success: function(data, status, xhr) {
							loginFlag=true;
							
							if(data.result==1){
//								sessionStorage.user_id=data.data.user_id;
//								sessionStorage.token=data.data.token;
								try{
									window.localStorage.setItem("user_id",data.data.user_id);
									window.localStorage.setItem("token",data.data.token);
									window.sessionStorage.setItem("user_id",data.data.user_id);
									window.sessionStorage.setItem("token",data.data.token);
									myTrav(data.data.token)
								}catch(e){
									alert("您处于无痕浏览，无法为您跳转");
									return;
								}
								
								
									
								//我的旅游专家以上
							}else{
								showToast(data.message)
							}
						},		
						error: function(xhr, status, thrown) {
							console.log(xhr);
						}
					});
				}
				function myTrav(token){
					//我的旅游专家以下
								//旅游专家 弹窗
								$.ajax({
									type:"post",
									url:url_enter+"/api/get_my_travel_mavin",
									async:false,
									headers:{
											"User-Token":token,
											"Os":ios_Andriod,
											"Screen": wh,
											"Device-Id":"",
											"Content-Type": "application/x-www-form-urlencoded"
									},
									data:{},
									success:function(data){
										if(data.result==1){//成功啦
											if(data.data.dep_id!=0){//用户存在旅游专家 则调用存在旅游专家的方法 live1;
												console.log(data.data.dep_id!=0)
												var obj4='{"dep_id":"'
												+data.data.dep_id+'","head_img":"'
												+data.data.head_img+'","names":"'
												+data.data.names+'","dep_name":"'
												+data.data.dep_name+'","phone_num":"'
												+data.data.phone_num+'","qq":"'
												+data.data.qq+'"}';
												console.log(obj4);
												sessionStorage.setItem("my_volg",obj4);
												if(GetQueryString('line_id')){
													window.location.href="index.html";
												}
												else if(document.referrer.indexOf("heart.html")){
													window.location.href="index.html";
												}
												else if(document.referrer && document.referrer!=sessionStorage.getItem("forgeturl")){
													sessionStorage.setItem('tourist_url',window.location.href);
													window.location.href=""+document.referrer+"";
												}else{
													window.location.href="index.html";
												}
											}else{
												var obj4="un";//若判断"my_volg"的值为"un"则不存在旅游专家 调用不存在旅游专家的方法 live2
												sessionStorage.setItem("my_volg",obj4);	
													if(GetQueryString('line_id')){
														window.location.href="index.html";
													}
													else if(document.referrer.indexOf("heart.html")){
														window.location.href="index.html";
													}
													else if(document.referrer && document.referrer!=sessionStorage.getItem("forgeturl")){
														sessionStorage.setItem('tourist_url',window.location.href);
														window.location.href=""+document.referrer+"";
													}else{
														window.location.href="index.html";
													}
													
											}
										}
									}
									
								});	
				}
				function myTr(token){
					//我的旅游专家以下
								//旅游专家 弹窗
								$.ajax({
									type:"post",
									url:url_enter+"/api/get_my_travel_mavin",
									async:false,
									headers:{
											"User-Token":token,
											"Os":ios_Andriod,
											"Screen": wh,
											"Device-Id":"",
											"Content-Type": "application/x-www-form-urlencoded"
									},
									data:{},
									success:function(data){
										if(data.result!=1){
											localStorage.removeItem('token');
											sessionStorage.removeItem('token');
											window.location.href='login.html'
										}
										else if(data.result==1){//成功啦
											if(data.data.dep_id!==0){//用户存在旅游专家 则调用存在旅游专家的方法 live1;
												var obj4='{"dep_id":"'
												+data.data.dep_id+'","head_img":"'
												+data.data.head_img+'","names":"'
												+data.data.names+'","dep_name":"'
												+data.data.dep_name+'","phone_num":"'
												+data.data.phone_num+'","qq":"'
												+data.data.qq+'"}';
												console.log(obj4);
												sessionStorage.setItem("my_volg",obj4);
//												if(!GetQueryString('from')){
//													var b=GetQueryString('from');
//													if(b=='information'){
//														history.back();
//													}
//												}
//												if(document.referrer && document.referrer!=sessionStorage.getItem("forgeturl")){
//													sessionStorage.setItem('tourist_url',window.location.href);
//													window.location.href=""+document.referrer+"";
//												}
												if(GetQueryString('line_id')){
													window.location.href="index.html";
												}
												if(document.referrer && document.referrer!=sessionStorage.getItem("forgeturl")){
													sessionStorage.setItem('tourist_url',window.location.href);
													window.location.href=""+document.referrer+"";
												}else{
													window.location.href="index.html";
												}
											}else{
												var obj4="un";//若判断"my_volg"的值为"un"则不存在旅游专家 调用不存在旅游专家的方法 live2
												sessionStorage.setItem("my_volg",obj4);	
												
													if(GetQueryString('line_id')){
														window.location.href="index.html";
													}
													if(document.referrer && document.referrer!=sessionStorage.getItem("forgeturl")){
														sessionStorage.setItem('tourist_url',window.location.href);
														window.location.href=""+document.referrer+"";
													}else{
														window.location.href="index.html";
													}
													
											}
										}
									}
									
								});	
				}
			});
		</script>
	</head>
	<body class="body">
		<div class="containter">
			<header data-am-widget="header" class="am-header am-header-default">
				<div class="am-header-left am-header-nav">
					<a href="javascript:;" onClick="javascript :history.back(-1);">
						<img src="assets/images/left.png">
					</a>
				</div>
				<h1 class="am-header-title" style="margin:0 14%">
      登录
    </h1>
			</header>
			<div style="height: 4rem; width: 100%;"></div>
			<div class="change login">
				<form action="">
					<img src="assets/images/head.png" alt="">
					<ul>
						<li class="zh">
							<input id="phonenumber" type="text" placeholder="请输入您的手机号码" maxlength="11">
						</li>
						<li>
							<input id="pass_word" type="password" placeholder="请输入您的密码">
							<a href="javascript:;" class="close"></a>
						</li>
					</ul>
					<div>
						<a href="forget_password.html" id="wangjimima">忘记密码？</a>
					</div>
					<button type="button" class="btn_login">登录</button>
					<button type="button" class="btn_register" id="jToreg">注册新用户</button>
					<!--<span>第三方登录</span>
					<ol>
						<li id="WxLogin">
							<a>
								<img src="assets/images/wx.png" alt="">微信
							</a>
						</li>
						<li id="qqLogin">
							<a>
								<img src="assets/images/Connect_logo_1.png" alt=""/>
							</a>
						</li>
					</ol>-->
				</form>
			</div>
		</div>
		<div id="toast"></div>
		<div id="QR_code"></div>
	</body>

</html>